
/* usbnapi.c
* Copyright (C) 2005  Benedikt Sauter
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _USBNAPI_H
#define _USBNAPI_H

#include "usbn960x.h"

#if !O_USB_TINY

#include <avr/pgmspace.h>

#ifdef ALL_IN_ONE
#include "usbn960xreg.h"
#include "usb11spec.h"
#else
#include "../usbn960xreg.h"
#include "../usb11spec.h"
#endif

//////////////////////////////////////////////////////////////////////////////

#define O_NEED_RAM_STRINGDESCRIPTORS		0

//////////////////////////////////////////////////////////////////////////////

typedef struct _endp_t   endp_t;
typedef struct _interf_t interf_t;
typedef struct _conf_t   conf_t;

//////////////////////////////////////////////////////////////////////////////

conf_t *USBNAddConfiguration2 (void);
interf_t *USBNAddInterfaceClass2 (conf_t *pc, uint8_t number, char class, char subclass, char protocol);
interf_t *USBNAddInterface2 (conf_t *pc, uint8_t number);

//////////////////////////////////////////////////////////////////////////////

/// initial global data structures
void    USBNInit (void);

/// define vendor/product/device id for usb function
void    USBNDeviceIDs (uint16_t idVendor, uint16_t idProduct, uint16_t bcdDevice);

/// define vendor id
void    USBNDeviceVendorID (uint16_t idVendor);

/// define product id
void    USBNDeviceProductID (uint16_t idProduct);

/// define device id e.g. 1.02 ( 0x0201 )
void    USBNDeviceBCDDevice (uint16_t bcdDevice);

void    USBNDeviceManufacture_P (const prog_char *manufature);
void    USBNDeviceProduct_P (const prog_char *product);
void    USBNDeviceSerialNumber_P (const prog_char *serialnumber);
void    USBNDeviceClass (uint8_t classcode);
void    USBNDeviceSubClass (uint8_t subclasscode);
void    USBNDeviceProtocol (uint8_t protocolcode);

conf_t   *USBNAddConfiguration (void);
void      USBNConfigurationName_P (conf_t *pc, const prog_char *name);
void      USBNConfigurationPower (conf_t *pc, uint16_t power);
interf_t *USBNAddInterfaceClass (conf_t *pc, uint8_t number, char class, char subclass, char protocol);
interf_t *USBNAddInterface (conf_t *pc, uint8_t number);
void      USBNAlternateSetting (conf_t *pc, interf_t *pi, uint8_t setting);
endp_t   *USBNAddOutEndpoint(conf_t *pc, interf_t *pi, uint8_t epnr, uint8_t epadr, char attr, uint8_t fifosize, uint8_t intervall, rxfunc_t *fkt);
endp_t   *USBNAddInEndpoint(conf_t *pc, interf_t *pi, uint8_t epnr, uint8_t epadr, char attr, uint8_t fifosize, uint8_t intervall, txfunc_t *fkt);

/// move descriptor tree in a linear array
void USBNCreateConfDescrField (void);

#if O_NEED_RAM_STRINGDESCRIPTORS
void    USBNDeviceManufacture (const char *manufature);
void    USBNDeviceProduct (const char *product);
void    USBNDeviceSerialNumber (const char *serialnumber);
void    USBNConfigurationName (conf_t *pc, const char *name);
#endif

#endif // !O_USB_TINY


const uint8_t *UsbGetDeviceDescriptor (void);
const uint8_t *UsbGetConfigDescriptor (uint8_t index);
const uint8_t *UsbGetString (uint8_t index);

#endif /* __USBNAPI_H__ */
